﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace WpfMesDemo2.Models
{
    public class Product : INotifyPropertyChanged
    {
        private int _id;
        private string _productId;
        private string _productName;
        private string _specification;
        private int _quantity;
        private DateTime _productionDate;
        private string _productionLine;
        private string _status;
        private bool _isDeleted;

        public int Id
        {
            get => _id;
            set => SetField(ref _id, value);
        }

        public string ProductId
        {
            get => _productId;
            set => SetField(ref _productId, value);
        }

        public string ProductName
        {
            get => _productName;
            set => SetField(ref _productName, value);
        }

        public string Specification
        {
            get => _specification;
            set => SetField(ref _specification, value);
        }

        public int Quantity
        {
            get => _quantity;
            set => SetField(ref _quantity, value);
        }

        public DateTime ProductionDate
        {
            get => _productionDate;
            set => SetField(ref _productionDate, value);
        }

        public string ProductionLine
        {
            get => _productionLine;
            set => SetField(ref _productionLine, value);
        }

        public string Status
        {
            get => _status;
            set => SetField(ref _status, value);
        }

        public bool IsDeleted
        {
            get => _isDeleted;
            set => SetField(ref _isDeleted, value);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        protected bool SetField<T>(ref T field, T value, [CallerMemberName] string propertyName = null)
        {
            if (EqualityComparer<T>.Default.Equals(field, value))
                return false;

            field = value;
            OnPropertyChanged(propertyName);
            return true;
        }
    }
}
